Import('env windows mongoClientStaticLibs libGTestStatic')

staticClientEnv = env.Clone()
staticClientEnv.PrependUnique(
    CPPDEFINES=[
        'STATIC_LIBMONGOCLIENT'
    ],
    LIBS=mongoClientStaticLibs,
)

libMock = staticClientEnv.StaticLibrary(
    target='mocklib',
    source=[
        "dbtests/mock/mock_conn_registry.cpp",
        "dbtests/mock/mock_dbclient_connection.cpp",
        "dbtests/mock/mock_dbclient_cursor.cpp",
        "dbtests/mock/mock_remote_db_server.cpp",
        "dbtests/mock/mock_replica_set.cpp",
    ],
)

libClientTestMain = staticClientEnv.StaticLibrary(
    target='client_test_main',
    source=[
        'unittest/client_test_main.cpp'
    ],
)

libIntegrationTestMain = staticClientEnv.StaticLibrary(
    target='integration_test_main',
    source=[
        'unittest/integration_test_main.cpp'
    ],
)

unittests = [
    'base/parse_number_test',
    'bson/bson_field_test',
    'bson/bson_obj_test',
    'bson/bson_validate_test',
    'bson/bsonobjbuilder_test',
    'bson/util/bson_extract_test',
    'client/connection_string_test',
    'client/dbclient_rs_test',
    'client/index_spec_test',
    'client/replica_set_monitor_test',
    'client/scoped_db_conn_test',
    'client/write_concern_test',
    'dbtests/jsobjtests',
    'dbtests/jsontests',
    'dbtests/mock_dbclient_conn_test',
    'dbtests/mock_replica_set_test',
    'dbtests/replica_set_monitor_test',
    'logger/log_test',
    'platform/atomic_word_test',
    'platform/process_id_test',
    'platform/random_test',
    'util/net/sock_test',
    'util/stringutils_test',
    'util/time_support_test',
]

gtestEnv = staticClientEnv.Clone()
gtestEnv.PrependUnique(
    # On windows, we need this odd flag to make the linker
    # search for main in our _test_main libs.
    LINKFLAGS=(['/SUBSYSTEM:CONSOLE'] if windows else []),
    LIBS=[
        libGTestStatic,
    ])

unitTestEnv = gtestEnv.Clone()
unitTestEnv.PrependUnique(
    LIBS=[
        libClientTestMain,
        libMock,
    ])

for unittest in unittests:
    unitTestEnv.CppUnitTest(
        target=unittest,
        source=[
            unittest + '.cpp'
        ])

integration_tests = [
    'bulk_operation_test',
    'dbclient_test',
    'dbclient_writer_test',
    'gridfs_test',
    'sasl_test'
]
integrationTestEnv = gtestEnv.Clone()
integrationTestEnv.PrependUnique(
    LIBS=[
        libIntegrationTestMain,
        libMock,
    ])

for integration_test in integration_tests:
    integrationTestEnv.IntegrationTest(
        target=integration_test,
        source=[
            'unittest/' + integration_test + '.cpp'
        ]
    )
